uniform sampler2D baseMap;
uniform sampler2D normalMap;
uniform sampler2D specularMap;

varying vec3 viewDirection;
varying vec3 lightDirection;

void main(void)
{
	/* Extract colors from baseMap and specularMap */
	vec4  baseColor = texture2D( baseMap, gl_TexCoord[0].xy );
    vec3  normal = normalize( ( texture2D( normalMap, gl_TexCoord[1].xy ).xyz * 2.0 ) - 1.0 );
    
    vec3 normalizedViewDirection = normalize( viewDirection );
		
	/* Sum up lighting models with OpenGL provided light/material properties */
    vec4 totalAmbient = gl_LightModel.ambient * gl_FrontMaterial.ambient;  // init with global ambient
    vec4 totalDiffuse; 
    vec4 totalSpecular;

    // ----------------------- LIGHT -----------------------
    
    vec3 normalizedLightDirection = normalize( lightDirection );
    float NDotL = dot( normal, normalizedLightDirection );
    vec3 reflection = normalize( ( ( 2.0 * normal ) * NDotL ) - normalizedLightDirection ); 
           
    /* Sum up lighting models with OpenGL provided light/material properties */
    totalAmbient  += gl_FrontLightProduct[0].ambient; 
    totalDiffuse  += clamp( gl_FrontLightProduct[0].diffuse * max( 0.0, NDotL ), 0.0, 1.0 ); 
    
	/* Set final pixel color as sum of lighting models */
    gl_FragColor = totalAmbient * baseColor + totalDiffuse * baseColor;
}
